package com.Xht.www.servlet;

//后端响应管理员处理商家入住平台申请的请求

import com.Xht.www.dao.MerchantInfoDAO;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/ProcessShopApplicationServlet")
public class ProcessShopApplicationServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("application/json;charset=UTF-8");
        PrintWriter out = response.getWriter();

        String action = request.getParameter("action");
        String merchantIdParam = request.getParameter("merchantId");

        try {
            int merchantId = Integer.parseInt(merchantIdParam);

            MerchantInfoDAO dao = new MerchantInfoDAO();
            boolean success = dao.processApplication(merchantId, action);

            if (success) {
                out.write("{\"success\": true}");
            } else {
                out.write("{\"success\": false, \"message\": \"处理申请失败\"}");
            }
        } catch (NumberFormatException e) {
            out.write("{\"success\": false, \"message\": \"商家ID格式错误\"}");
        } catch (Exception e) {
            out.write("{\"success\": false, \"message\": \"服务器内部错误\"}");
            e.printStackTrace();
        }
    }
}
